from . import api_blueprint
from flask import request, json
from app import db
from app.model.teacher import Teacher


@api_blueprint.route('/teacher/all', methods=['GET'])
def get_all_teachers():
    results = Teacher.query.all()
    # print(courses)
    return json.dumps(results, default=Teacher.to_json)


@api_blueprint.route('/teacher', methods=['GET'])
def get_teacher_by_log_id():
    log_id = request.values.get('log_id')
    if log_id is None:
        return json.dumps({
            'status': 'error',
            'msg': 'log_id is missing'
        }), 400
    row = Teacher.filter(Teacher.Tea_log_id == log_id).first()
    if row is None:
        return json.dumps({
            'status': 'error',
            'msg': 'teacher is not found'
        }), 404
    return json.dumps(row, default=Teacher.to_json)
